package com.gym.controller;

import com.github.pagehelper.Page;
import com.gym.pojo.Equipmentupkeep;
import com.gym.service.EquipmentupkeepService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class EquipmentUpKeepController {

    @Resource
    private EquipmentupkeepService equipmentupkeepService;

    /*
     * 查询全部器材维修信息
     * */
    @PostMapping("/selAllUpKeep")
    public Map<String,Object> selAllUpKeep(@RequestParam Integer pageIndex,
                            @RequestParam(required = false) String equname,
                            @RequestParam(required = false) String start,
                            @RequestParam(required = false) String end) {
        List<Equipmentupkeep> list = equipmentupkeepService.selAllUpKeep(pageIndex,equname,start,end);
        int count = equipmentupkeepService.selRepairCount(equname,start,end);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("data",list);
        map.put("count",count);
        map.put("code",0);
        map.put("msg","1");
        return map;
    }

    /**
     * 添加器材维修信息
     * @param equipmentupkeep
     * @return
     */
    @PostMapping("/addEquRepair")
    public boolean addEquRepair(@SpringQueryMap Equipmentupkeep equipmentupkeep) {
        return equipmentupkeepService.addEquRepair(equipmentupkeep);
    }


    /*
     * 修改器材维修信息
     * */
    @PostMapping("/updateEquRepair")
    public boolean updateEquRepair(@RequestBody Equipmentupkeep equipmentupkeep) {
        return equipmentupkeepService.updateEquRepair(equipmentupkeep);
    }


    /*
     * 删除器材维修信息
     * */
    @PostMapping("/delEquRepair")
    public boolean delEquRepair(@RequestParam String equkeepid) {
        return equipmentupkeepService.delEquRepair(equkeepid);
    }

}
